<?php 
include_once(''.P.'/public/header.html');
?>

<script type="text/javascript" src="res/bootstrapplugin/jquery-bootstable.js"></script>


<script>
function initbody(){
	
}
function save(o1){
	var da = js.getformdata();
	da.type = '<?=$type?>';
	da.device = device;
	js.setmsg('保存中...');
	o1.disabled=true;
	js.ajax({
		type:'post',
		url:'?m=cog&a=savecheck&d=manage&cnum='+cnum+'',
		data:da,
		success:function(res){
			o1.disabled=false;
			if(res=='ok'){
				js.setmsg('保存成功','green');
				if(da.type=='jiesan'){
					js.setmsg('已解散','green');
					js.msgok('单位已解散',function(){
						js.location('?m=index');
					},2);
				}
			}else{
				js.setmsg(res);
			}
		}
	});
}

function reloadkey(){
	js.loading('更新中...');
	$.get('?m=cog&a=updatesecret&d=manage&cnum='+cnum+'',function(){
		js.reload();
	});
}
</script>
<style>
.caidan{padding:10px;text-align:left;border-bottom:1px #eeeeee solid;cursor:pointer}
.caidan:hover{background-color:rgba(0,0,0,0.05)}
.caidan.active{background-color:rgba(0,0,0,0.06)}
</style>
</head>

<body>

<?php 
include_once(''.P.'/public/top_manage.html');
?>

<div align="center">

<div style="width:<?=$maxwidth?>;margin:20px 0px" align="left">
	<div style="color:#cccccc">
		<a href="?d=manage&cnum=<?=$cnum?>" class="zhu"><?=lang('manage.home')?></a> &gt;
		<a href="" class="zhu"><?=lang('manage.cogtitle')?></a>
	</div>
	
	<div class="mainbody">
	
	<table width="100%">
	<tr valign="top">
	<td style="background:#f9f9f9;min-height:500px;border-right:1px #f1f1f1 solid">
	<div style="width:180px;min-height:500px;">
		
		<div class="caidan<?php if(isempt($type))echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=cog">单位信息</a></div>
		
		<div class="caidan<?php if($type=='hdiao')echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=cog&type=hdiao">回调设置</a></div>
		
		<div class="caidan<?php if($type=='create')echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=cog&type=create">单位创建人</a></div>
		<div class="caidan<?php if($type=='jiesan')echo ' active';?>">◇ <a href="?d=manage&cnum=<?=$cnum?>&m=cog&type=jiesan">单位解散</a></div>
	
		
	</div>
	</td>
	
	<td width="90%">
	
	<?php if(isempt($type)){?>
	<div style="padding:30px 30px">
		<form name="myform">
		<table>
	
		
		<tr><td align="right" style="color:gray">单位ID：</td><td><?=$companyinfo['id']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位编号：</td><td><?=$companyinfo['num']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位secret：</td><td><?php
		$secret = $companyinfo['secret'];
		if(!isempt($secret))$secret = substr($secret,0,5).'*****'.substr($secret,-5);
		echo '<span>'.$secret.'</span>';
		?>&nbsp;<a href="javascript:;" class="zhu" onclick="reloadkey()">[更新]</a>&nbsp;<a href="javascript:;"  class="zhu" onclick="js.setcopy('<?=$companyinfo['secret']?>')">[复制]</a></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">用户容量：</td><td><?=$companyinfo['flaskm']?>/<?=$companyinfo['flasks']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">创建时间：</td><td><?=$companyinfo['createdt']?></td></tr>
		<tr><td height="10"></td></tr>
		
	
		<tr>
			<td align="right" style="color:gray">单位Logo：</td>
			<td>
			<img src="<?=$companyinfo['logo']?>" id="logoshow_img" style="border-radius:50%" width="80px" height="80px"><br>
			<input style="width:260px" name="logo" id="logoshow" type="hidden" class="input" value="<?=$companyinfo['logo']?>">
			<button type="button" class="webbtn webbtn-mini" onclick="js.updateface('单位Logo','logoshow');">上传</button>
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray"><font color=red>*</font>单位名称：</td><td><input name="name" type="text" value="<?=$companyinfo['name']?>" style="width:260px" class="input"></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位简称：</td><td><input name="shortname" type="text" value="<?=$companyinfo['shortname']?>" style="width:260px" class="input"></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">联系人：</td><td><input name="contacts" type="text" value="<?=$companyinfo['contacts']?>" style="width:260px" class="input"></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">电话：</td><td><input name="tel" type="text" value="<?=$companyinfo['tel']?>" style="width:260px" class="input"></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right"></td><td>
		<button type="button" onClick="save(this)" style="padding:8px 20px;border-radius:5px" class="webbtn" >保存</button>&nbsp;<span id="msgview"></span>
		</td></tr>
		
		</table>
		
		</form>
	</div>
	<?php }?>
	
	
	<?php if($type=='hdiao'){?>

	<div style="padding:30px 30px">
		<form name="myform">
		<table>
		
		<tr><td align="right" style="color:gray"></td><td>回调就是单位管理中有些数据改变回调通知给设置地址，看<a class="zhu" href="<?=URLY?>view_reimhdiao.html" target="_blank">帮助</a>开发</td></tr>
		<tr><td height="10"></td></tr>

		<tr><td align="right" style="color:gray">回调地址：</td><td><textarea name="hdiaourl" type="text" style="width:410px;height:70px" class="input" placeholder="多个地址,分开"><?=$companyinfo['hdiaourl']?></textarea></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">回调KEY：</td><td><textarea name="hdiaokey" type="text" style="width:410px;height:60px" class="input" placeholder="接收到消息需要这个解密"><?=$companyinfo['hdiaokey']?></textarea></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right"></td><td>
		<button type="button" onClick="save(this)" style="padding:8px 20px;border-radius:5px" class="webbtn" >保存</button>&nbsp;<span id="msgview"></span>
		</td></tr>
		
		</table>
		
		</form>
	</div>
	<?php }?>
	
	
	
	<?php if($type=='create'){?>
	<script type="text/javascript" src="res/js/jquery-changeuser.js"></script>
	<div style="padding:30px 30px">
		<form name="myform">
		<table>

		<tr><td align="right" style="color:gray">单位ID：</td><td><?=$companyinfo['id']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位编号：</td><td><?=$companyinfo['num']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位名称：</td><td><?=$companyinfo['name']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">创建人：</td><td><?=$cjinfo['name']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr>
			<td align="right" style="color:gray">修改为：</td>
			<td>
				<input style="width:150px" readonly id="changecreatename" name="createname" class="input" value=""><button type="button" class="webbtn"  onclick="js.changeuser('changecreatename','user','选择新的创建人')">选择</button>
				<input type="hidden" name="createid" id="changecreatename_id" class="input" value="">
			</td>
		</tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right"></td><td>
		<button type="button" onClick="save(this)" style="padding:8px 20px;border-radius:5px" class="webbtn" >保存</button>&nbsp;<span id="msgview"></span>
		</td></tr>
		
		</table>
		
		</form>
	</div>
	<?php }?>
	
	<?php if($type=='jiesan'){?>
	<div style="padding:30px 30px">
		<form name="myform">
		<table>

		<tr><td align="right" style="color:gray">单位ID：</td><td><?=$companyinfo['id']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位编号：</td><td><?=$companyinfo['num']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">单位名称：</td><td><?=$companyinfo['name']?></td></tr>
		<tr><td height="10"></td></tr>
		
		<tr><td align="right" style="color:gray">创建人：</td><td><?=$cjinfo['name']?></td></tr>
		<tr><td height="10"></td></tr>
		
		
		<tr><td align="right" style="color:gray">创建人手机号：</td><td>
		<?php
		$mobile = $cjinfo['mobile'];
		if(!isempt($mobile))$mobile = substr($mobile,0,3).'*****'.substr($mobile,-4);
		echo ''.$mobile.'';
		?>
		<input name="mobile" value="<?=$cjinfo['mobile']?>" type="hidden">
		<input name="mobilecode" value="" type="hidden">
		</td></tr>
		<tr><td height="10"></td></tr>
		
		<tr>
			<td align="right" style="color:gray">计算验证：</td>
			<td align="left">
			<input placeholder="请输入计算结果" maxlength="2" style="width:130px;border-radius:5px 0px 0px 5px;border-right:0px;" class="input" name="imgcode"><div style="height:34px;width:70px;border:1px #dddddd solid;float:right;border-radius:0px 5px 5px 0px;cursor:pointer;"><img onclick="reshuacode()" id="imgcodeimg" align="absmiddle" src=""></div>
			</td>
		</tr>
		<tr><td height="10px"></td></tr>
		
		<tr>
			<td align="right" style="color:gray">短信验证码：</td>
			<td>
			<input maxlength="6" placeholder="短信验证码" style="width:131px;border-radius:5px 0px 0px 5px;border-right:0px;" class="input" name="smscode"><input type="button" style="height:36px;width:70px;border:1px #dddddd solid;border-radius:0px 5px 5px 0px;background:#f1f1f1;cursor:pointer;" onclick="getcode()" id="getcodebtn" value="获取">
			
			</td>
		</tr>
		<tr><td height="10px"></td></tr>

		
		<tr><td align="right"></td><td>
		<button type="button" onClick="save(this)" style="padding:8px 20px;border-radius:5px" class="webbtn" >确定解散</button>&nbsp;<span id="msgview"></span>
		</td></tr>
		
		</table>
		<div style="color:blue;margin:10px">解散后就会删除全部单位相关数据，无法恢复，谨慎操作！</div>
		</form>
	</div>
	
<script>
function initbody(){
	reshuacode();
}
function reshuacode(){
	var url = js.apiurl('login','imgcode', {device:device});
	var o1 = get('imgcodeimg');
	o1.src = url;
}
function getcode(){
	js.setmsg();
	var da = js.getformdata();
	if(!da.mobile){
		js.msg('msg','请输入手机号');
		form('mobile').focus();
		return;
	}
	if(!da.mobilecode && da.mobile.length!=11){
		js.msg('msg','请输入11位手机号');
		form('mobile').focus();
		return;
	}
	if(!da.imgcode){
		js.msg('msg','请输入计算验证结果');
		form('imgcode').focus();
		return;
	}
	var o1 = get('getcodebtn');
	o1.disabled=true;
	o1.value='获取中..';
	js.ajax({
		url:js.apiurl('login','getcode'),
		data:{device:device,gtype:'san',mobilecode:da.mobilecode,mobile:da.mobile,imgcode:da.imgcode},
		type:'post',
		dataType:'json',
		success:function(ret){
			if(ret.success){
				o1.value='获取成功';
				js.msg('success',ret.data.msg);
				dshitime(60, o1);
			}else{
				js.msg('msg',ret.msg);
				o1.disabled=false;
				o1.value='重新获取';
			}
			reshuacode();
		},
		error:function(){
			js.msg('msg','获取失败');
			o1.disabled=false;
			o1.value='重新获取';
		}
	});
}

function dshitime(sj,o1){
	if(sj==0){
		o1.disabled=false;
		o1.value='重新获取';
		return;
	}
	o1.disabled=true;
	o1.value=''+sj+'';
	setTimeout(function(){dshitime(sj-1, o1)},1000);
}
</script>

	<?php }?>
	
	
	
	</td>
	</tr>	
	</table>


	</div>
</div>



<?php 
include_once(''.P.'/public/footer.html');
?>
</div>

</body>
</html>